/*
 * 查询上传成功的文件 
 */
var pageSize = 10;
var pageIndex = 0;
var searchInput = {
	videoName: "",
	regionCode: ""
}

function search() {
	var name = document.querySelector("#searchVideoName").value;
	var regionCode = document.querySelector("#searchRegionCode").value;
	searchInput.videoName = name;
	searchInput.regionCode = regionCode;
	var list = [];
	list.push(regionCode);
	var params = {
		name: name,
		regionCode: list,
		pageSize: "10",
		pageIndex: "0"
	}
	getVideoList(params);
	pageIndex = 0;
}

function prePage() {
	if(pageIndex == 0) {
		return;
	} else {
		var list = [];
		list.push(searchInput.regionCode);
		var params = {
			name: searchInput.videoName,
			regionCode: list,
			pageSize: "10",
			pageIndex: pageIndex - 1
		}
		getVideoList(params);
	}
}

function nextPage() {
	var list = [];
	list.push(searchInput.regionCode);
	var params = {
		name: searchInput.videoName,
		regionCode: list,
		pageSize: "10",
		pageIndex: pageIndex + 1
	}
	getVideoList(params);
}

function getVideoList(params) {
	ajax({
		url: "/xstore-vod-demo/video/search",
		type: "post",
		contentType: "application/json",
		data: JSON.stringify(params),
		dataType: "json",
		success: function(responseText) {
			var res = JSON.parse(responseText);
			if(res.code == "0") {
				var html = "";
				var list = res.data;
				if(list.length == 0) {
					if(params.pageIndex == "0") {
						var tbody = document.querySelector("#video-list");
						tbody.innerHTML = "";
					}
				} else {
					for(var i = 0; i < list.length; i++) {
						html += "<tr><td>" + list[i].videoId + "</td><td>" + list[i].name + "</td><td>" + list[i].region.name
									+ "</td><td>" + list[i].status + "</td><td>" + list[i].createTime + "</td></tr>"
					}
					var tbody = document.querySelector("#video-list");
					tbody.innerHTML = html;
					if(pageIndex != params.pageIndex) {
						pageIndex = params.pageIndex;
					}
				}
				document.querySelector("#page-index").innerText = "第" + (pageIndex+1) + "页";
			}
		},
		error: function(status) {
			
		}
	});
}